package datas
{
	import assists.log.Log;
	
	import main.DataSubBase;
	
	import struct.CityStruct;
	
	public class CityListData extends DataSubBase
	{
		private var cityList:Array;
		private var scenicList:Array;
		
		private var choosenCity:String;
		
		public function CityListData()
		{
			cityList = [];
			scenicList = [];
		}
		
		public function loadList():void
		{
			cityList = [];
			scenicList = [];
			
			xmlLoader.cityListXml.initThis(function():void{
				
				var list:Array = xmlLoader.cityListXml.load("city");
				for(var i:int = 0;i < list.length;i++){
					var obj:CityStruct = new CityStruct();
					obj.init(data.uri,data.xmlLoaderManager);
					obj.initWithData(list[i]);
					
					if(obj.type == 1){
						cityList.push(obj);
					}else{
						scenicList.push(obj);
					}
				}
				
				for(var j:int = 0;j < cityList.length;j++){
					var smallList:Array = [];
					var str:String = cityList[j].childrenList;
					smallList = str.split("-");
					
					cityList[j].scenicList = [];
					
					for(var k:int = 0;k < smallList.length;k++){
						for(var l:int = 0;l < scenicList.length;l++){
							if(smallList[k] == scenicList[l].id){
								cityList[j].scenicList.push(scenicList[l]);
							}
						}
					}
				}
				
				Log.trace("啊哈哈哈" + cityList);	
			})
		}
		
		public function get currentCityInfo():CityStruct
		{
			for(var i:int = 0;i < cityList.length;i++){
				if(cityList[i].id == choosenCity){
					return cityList[i];
				}
			}
			return null;
		}
		
		public function get allList():Array
		{
			return cityList;
		}
		
		
		public function set chooseCityId(num:String):void
		{
			choosenCity = num;
			
			var current:CityStruct = currentCityInfo;
			if(current){
				data.uri.cityPath = current.fileName;
			}
		}
		
		public function get chooseCity():String
		{
			return choosenCity;
		}
	}
}